
class MainBGUI extends egret.Sprite {
	public constructor() {
		super();
		this.once(egret.Event.ADDED_TO_STAGE, this.createView, this);
	}
	private createView(): void {

		//音乐图标
		// var music_logo = createBitmap("music_logo_png", 80, 50);
		var music_logo = createBitmap("music_logo_png", 32.5, 32.5);
		this.$stage.addChild(music_logo);
		music_logo.anchorOffsetX = 65 * .5;
		music_logo.anchorOffsetY = 65 * .5;
		var tw = egret.Tween.get(music_logo, { loop: true }).to({ rotation: 360 }, 2000);
		music_logo.touchEnabled = true;
		//声音加载
		var sound = new egret.Sound;
		var soundChannel;
		var music_Length = 0;
		var curTime = 0;
		sound.addEventListener(egret.Event.COMPLETE, function () {
			soundChannel = sound.play(curTime, 0);
			music_Length = sound.length;
		}, this);
		sound.load("resource/assets/music.mp3");
		//实现点击music_logo图标播放/暂停功能
		music_logo.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
			if (soundChannel === null) {
				soundChannel = sound.play(curTime);
				soundChannel.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
				})
				egret.Tween.resumeTweens(music_logo);
			} else {
				curTime = soundChannel.position;
				soundChannel.stop();
				soundChannel = null;
				egret.Tween.pauseTweens(music_logo);
			}
		}, this);
	}
}